(function(){"use strict";BX.namespace("BX.Main");BX.Main.selectorManagerV2={getById:function(t){if(typeof this.controls[t]!="undefined"){return this.controls[t]}return null},controls:{},loadedEntities:{}};BX.Main.SelectorV2=function(){this.initialized=false;this.blockInit=false;this.id="";this.apiVersion=2;this.fieldName=null;this.inputId=null;this.input=null;this.tagId=null;this.tag=null;this.options=null;this.callback=null;this.callbackBefore=null;this.items=null;this.entities=null;this.mainPopupWindow=null;this.entitiesSet=["users","emails","crmemails","groups","sonetgroups","department","departmentRelation","contacts","companies","leads","deals"];this.entityTypes={};this.auxObject=null;this.selectorInstance=null;this.eventOpenBinded=false};BX.Main.SelectorV2.controls={};BX.Main.SelectorV2.create=function(t){if(typeof t.id=="undefined"||!t.id){t.id=BX.util.hashCode(Math.random().toString())}else if(typeof BX.Main.selectorManagerV2.controls[t.id]!="undefined"){var e=BX.Main.selectorManagerV2.controls[t.id];if(e.bindNode&&!document.body.contains(e.bindNode)){delete BX.Main.selectorManagerV2.controls[t.id]}else{return BX.Main.selectorManagerV2.controls[t.id]}}var i=new BX.Main.SelectorV2;BX.Main.selectorManagerV2.controls[t.id]=i;i.init(t);return i};BX.Main.SelectorV2.proxyCallback=function(t,e){t(e)};BX.Main.SelectorV2.prototype={init:function(t){this.id=t.id;this.apiVersion=t.apiVersion&&parseInt(t.apiVersion)>=2?parseInt(t.apiVersion):2;this.fieldName=t.fieldName?t.fieldName:null;this.inputId=t.inputId?t.inputId:null;this.input=t.inputId&&BX(t.inputId)?BX(t.inputId):null;this.inputBox=t.inputBoxId&&BX(t.inputBoxId)?BX(t.inputBoxId):null;this.inputItemsContainer=t.inputContainerId&&BX(t.inputContainerId)?BX(t.inputContainerId):null;this.containerNode=t.containerId&&BX(t.containerId)?BX(t.containerId):null;this.bindNode=t.bindId&&BX(t.bindId)?BX(t.bindId):this.containerNode;this.tagId=t.tagId?t.tagId:null;this.tag=t.tagId&&BX(t.tagId)?BX(t.tagId):null;this.openDialogWhenInit=typeof t.openDialogWhenInit=="undefined"||!!t.openDialogWhenInit;this.options=t.options||{};this.callback=t.callback||null;this.callbackBefore=t.callbackBefore||null;this.items=t.items||null;this.entities=t.entities||null;this.entityTypes={};BX.onCustomEvent("BX.Main.SelectorV2:onGetEntityTypes",[{selector:this}]);this.selectorInstance=BX.UI.Selector.create({id:this.id,fieldName:this.fieldName,type:"xxx",pathToAjax:BX.type.isNotEmptyString(t.pathToAjax)?t.pathToAjax:null,input:this.input||null,tag:this.tag||null,inputBox:this.inputBox||null,inputItemsContainer:this.inputItemsContainer||null,entities:BX.clone(this.entityTypes),itemsSelected:BX.clone(this.items.selected)||{},itemsUndeletable:BX.clone(this.items.undeletable)||[],options:{multiple:this.getOption("multiple"),useSearch:this.getOption("useSearch"),useContainer:this.getOption("useContainer")=="Y"?"Y":"N",userNameTemplate:this.getOption("userNameTemplate"),siteDepartmentId:this.getOption("siteDepartmentId"),showCloseIcon:"Y",popupAutoHide:this.getOption("popupAutoHide")=="N"?"N":"Y",last:{disable:this.getOption("disableLast")=="Y"?"Y":"N"},search:{useAjax:this.getOption("sendAjaxSearch")!="N"?"Y":"N",useClientDatabase:this.getOption("useClientDatabase")=="Y"?"Y":"N"},focusInputOnSelectItem:this.getOption("focusInputOnSelectItem")!="N"?"Y":"N",focusInputOnSwitchTab:this.getOption("focusInputOnSwitchTab")!="N"?"Y":"N",isCrmFeed:this.getOption("isCrmFeed")=="Y"?"Y":"N",tagLink1:this.getOption("tagLink1"),tagLink2:this.getOption("tagLink2")},bindOptions:{node:this.bindNode,offsetTop:5,offsetLeft:15,zIndex:parseInt(this.getOption("popupZIndex"))>0?parseInt(this.getOption("popupZIndex")):1200},callback:this.callback,callbackBefore:this.callbackBefore});BX.addCustomEvent("BX.UI.SelectorManager:getTreeItemRelation",function(t){if(this.id==t.selectorId){this.getTreeItemRelation(t)}}.bind(this));BX.addCustomEvent("BX.UI.SelectorManager:loadAll",function(t){this.loadAll(t)}.bind(this));BX.addCustomEvent("BX.Main.SelectorV2:initDialog",function(t){if(this.id==t.selectorId){if(!!t.openDialogWhenInit){this.openDialogWhenInit=true}this.initDialog()}}.bind(this));BX.addCustomEvent("BX.Main.SelectorV2:reInitDialog",function(t){if(this.id==t.selectorId){this.initialized=false;this.items.selected=BX.type.isNotEmptyObject(t.selectedItems)?t.selectedItems:{};this.items.undeletable=BX.type.isNotEmptyObject(t.undeletableItems)?t.undeletableItems:{};var e=BX.UI.SelectorManager.instances[t.selectorId],i=null,n=null,s=0;if(e){for(var o in e.itemsSelected){if(e.itemsSelected.hasOwnProperty(o)){i=e.itemsSelected[o].toUpperCase();n=BX.UI.SelectorManager.getEntityTypeFullList(i);for(s=0;s<n.length;s++){if(BX.type.isNotEmptyObject(e.entities[n[s]])){e.unselectItem({itemNode:BX.type.isNotEmptyObject(e.entities[n[s]].items)&&BX.type.isNotEmptyObject(e.entities[n[s]].items[o])?e.entities[n[s]].items[o]:false,itemId:o,entityType:n[s],mode:"reinit"})}}}}e.itemsSelected=this.items.selected;e.itemsUndeletable=this.items.undeletable}this.initDialog()}}.bind(this));BX.addCustomEvent("BX.UI.SelectorManager:searchRequest",function(t){if(this.id==t.selectorInstance.id){t.selectorInstance.timeouts.search=setTimeout(function(){this.searchRequest(t)}.bind(this),1e3)}}.bind(this));BX.addCustomEvent("BX.UI.Selector:onSelectItem",function(t){if(this.apiVersion>=3&&BX.type.isNotEmptyObject(t)&&this.id==t.selectorId&&BX.type.isNotEmptyString(t.itemId)){this.saveDestination({itemId:t.itemId})}}.bind(this));if(!BX.type.isNotEmptyString(this.getOption("lheName"))){var e=BX("div"+this.getOption("lheName"));if(e){BX.addCustomEvent(e,"OnShowLHE",function(t){if(!t){this.selectorInstance.closeAllPopups()}}.bind(this))}}if(this.getOption("useContainer")!="Y"&&this.input){if(this.getOption("lazyLoad")!="Y"||BX.type.isNotEmptyObject(this.items.selected)){if(BX.type.isNotEmptyObject(this.items.selected)){this.openDialogWhenInit=false}this.initDialog()}if(this.tag){BX.bind(this.tag,"focus",BX.delegate(function(t){this.initDialog({realParams:true,bByFocusEvent:true});return t.preventDefault()},this));this.selectorInstance.setTagTitle()}BX.bind(this.input,"keydown",function(t){this.selectorInstance.getSearchInstance().beforeSearchHandler({event:t})}.bind(this));BX.bind(this.input,"bxchange",function(e){setTimeout(function(){this.selectorInstance.getSearchInstance().searchHandler({event:e,tagInputName:t.tagId})}.bind(this),0)}.bind(this));this.input.setAttribute("data-bxchangehandler","Y")}else if(this.getOption("useContainer")=="Y"&&(this.getOption("lazyLoad")!="Y"||this.getOption("useContainer")=="Y")){this.initDialog()}if(this.items.hidden){for(var i in this.items.hidden){if(this.items.hidden.hasOwnProperty(i)){this.callback.select.apply({id:(typeof this.items.hidden[i]["PREFIX"]!="undefined"?this.items.hidden[i]["PREFIX"]:"SG")+this.items.hidden[i]["ID"],name:this.items.hidden[i]["NAME"]},typeof this.items.hidden[i]["TYPE"]!="undefined"?this.items.hidden[i]["TYPE"]:"sonetgroups","",true,"","init")}}}},show:function(){this.initDialog()},initDialog:function(t){if(typeof t=="undefined"||typeof t.realParams=="undefined"){t=null}if(this.blockInit){return}var e={id:this.id};if(!this.initialized){BX.onCustomEvent(window,"BX.Main.SelectorV2:beforeInitDialog",[e])}setTimeout(BX.delegate(function(){if(typeof e.blockInit=="undefined"||e.blockInit!==true){if(this.initialized){if(!this.mainPopupWindow||!this.mainPopupWindow.isShown()){if(this.input){this.input.style.display="inline-block"}if(this.inputBox){this.inputBox.style.display="inline-block"}this.openDialog(t)}}else{this.getData(BX.delegate(function(e){if(!!this.openDialogWhenInit){if(this.input){this.input.style.display="inline-block"}if(this.inputBox){this.inputBox.style.display="inline-block"}this.openDialog(t)}BX.onCustomEvent(window,"BX.Main.SelectorV2:afterInitDialog",[{id:this.id}]);if(typeof this.options.eventOpen!="undefined"&&!this.eventOpenBinded){this.eventOpenBinded=true;BX.addCustomEvent(window,this.options.eventOpen,function(t){if(typeof t.id=="undefined"||t.id!=this.id){return}if(this.options.multiple!="Y"&&this.inputItemsContainer&&this.inputItemsContainer.children.length>0){return}if(this.mainPopupWindow&&this.mainPopupWindow.isShown()){return}if(this.input){this.input.style.display="inline-block"}if(this.inputBox){this.inputBox.style.display="inline-block"}var e=BX.type.isNotEmptyObject(t)&&t.bindNode?t.bindNode:this.bindNode;var i=BX.type.isNotEmptyObject(t)&&BX.type.isNotEmptyObject(t.bindPosition)?t.bindPosition:false;if(e){var n=BX.findChild(e,{tagName:"input",attr:{type:"text"}},true);if(n){this.selectorInstance.nodes.input=n;var s=this.tag||BX(t.tagId);if(s){this.selectorInstance.nodes.tag=s}if(n.getAttribute("data-bxchangehandler")!=="Y"){BX.bind(n,"keydown",function(t){this.selectorInstance.getSearchInstance().beforeSearchHandler({event:t})}.bind(this));BX.bind(n,"bxchange",function(t){this.selectorInstance.getSearchInstance().searchHandler({event:t})}.bind(this));n.setAttribute("data-bxchangehandler","Y")}}}if(i||e){if(!this.initialized){this.selectorInstance.itemsSelected={}}if(typeof t.value!="undefined"){this.selectorInstance.itemsSelected=t.value}this.openDialog({bindNode:e,bindPosition:i})}}.bind(this))}},this))}}},this),1)},openDialog:function(t){if(BX.type.isNotEmptyObject(t)){if(typeof t.bindNode!="undefined"){this.selectorInstance.bindOptions.node=t.bindNode}if(typeof t.bindPosition!="undefined"){this.selectorInstance.bindOptions.position=t.bindPosition}}this.selectorInstance.openDialog();this.mainPopupWindow=this.getOption("useContainer")=="Y"?this.selectorInstance.popups.container:this.selectorInstance.popups.main},closeDialog:function(){this.selectorInstance.closeDialog()},getData:function(t){this.blockInit=true;BX.onCustomEvent("BX.Main.SelectorV2:onGetDataStart",[this.id]);BX.ajax.runComponentAction("bitrix:main.ui.selector","getData",{mode:"ajax",data:{options:this.options,entityTypes:this.entityTypes,selectedItems:this.items.selected||{}}}).then(function(e){if(BX.type.isNotEmptyObject(e.data)){this.blockInit=false;BX.onCustomEvent("BX.Main.SelectorV2:onGetDataFinish",[this.id]);this.addData(e.data,t);this.initialized=true}}.bind(this),function(t){this.blockInit=false;BX.onCustomEvent("BX.Main.SelectorV2:onGetDataFinish",[this.id])}.bind(this))},loadAll:function(t){var e=BX.type.isNotEmptyString(t.entity)?t.entity.toUpperCase():"USERS";if(BX.type.isNotEmptyObject(t)&&BX.type.isFunction(t.callback)&&!BX.Main.selectorManagerV2.loadedEntities[e]){BX.Main.selectorManagerV2.loadedEntities[e]=true;BX.ajax.runComponentAction("bitrix:main.ui.selector","loadAll",{mode:"ajax",data:{entityType:e}}).then(function(e){if(BX.type.isNotEmptyObject(e.data)){for(var i in e.data){if(e.data.hasOwnProperty(i)){BX.onCustomEvent("onFinderAjaxLoadAll",[e.data[i],BX.UI.SelectorManager,i.toLowerCase()])}}t.callback()}}.bind(this),function(t){}.bind(this))}},searchRequest:function(t){this.blockInit=true;if(this.selectorInstance.timeouts.search){clearTimeout(this.selectorInstance.timeouts.search)}var e=new Date;this.selectorInstance.searchRequestId=e.getTime();BX.ajax.runComponentAction("bitrix:main.ui.selector","doSearch",{mode:"ajax",data:{searchString:t.searchString,searchStringConverted:BX.message("LANGUAGE_ID")=="ru"&&BX.correctText?BX.correctText(t.searchString):"",currentTimestamp:this.selectorInstance.searchRequestId,options:this.options,entityTypes:this.entityTypes,additionalData:BX.type.isNotEmptyObject(t.additionalData)?t.additionalData:{}},onrequeststart:function(t){this.selectorInstance.searchXhr=t}.bind(this)}).then(function(e){this.blockInit=false;if(BX.type.isNotEmptyObject(e.data)&&e.data.currentTimestamp&&e.data.currentTimestamp==this.selectorInstance.searchRequestId&&BX.type.isNotEmptyObject(t.callback)&&BX.type.isFunction(t.callback.success)){t.callback.success(e.data,{searchString:t.searchString,searchStringOriginal:BX.type.isNotEmptyObject(t.searchStringOriginal)?t.searchStringOriginal:t.searchString})}}.bind(this),function(e){this.blockInit=false;if(BX.type.isNotEmptyObject(t.callback)&&BX.type.isFunction(t.callback.failure)){t.callback.failure(BX.type.isNotEmptyObject(e.data)?e.data:{})}}.bind(this))},getTreeItemRelation:function(t){BX.ajax.runComponentAction("bitrix:main.ui.selector","getTreeItemRelation",{mode:"ajax",data:{entityType:t.entityType,categoryId:t.categoryId,allowSearchSelf:t.allowSearchSelf}}).then(function(e){if(BX.type.isNotEmptyObject(e.data)&&typeof t.callback!="undefined"){t.callback({selectorInstanceId:this.selectorInstance.id,entityType:t.entityType,categoryId:t.categoryId,data:e.data})}}.bind(this),function(t){})},addData:function(t,e){BX.onCustomEvent("BX.Main.SelectorV2:onAddData",[this.id,t]);if(typeof t.ENTITIES.CRM!="undefined"&&typeof t.ENTITIES.CRM.ITEMS_LAST!="undefined"&&BX.type.isNotEmptyObject(t.ENTITIES.CRM.ITEMS_LAST)){}e.apply(this,t)},getId:function(){return this.id},getOption:function(t){return typeof this.options[t]!="undefined"?this.options[t]:null},saveDestination:function(t){if(BX.type.isNotEmptyObject(t)&&BX.type.isNotEmptyString(t.itemId)){var e=this.getOption("context");if(BX.type.isNotEmptyString(e)){BX.ajax.runComponentAction("bitrix:main.ui.selector","saveDestination",{mode:"ajax",data:{context:e,itemId:t.itemId}}).then(function(t){},function(t){})}}}}})();
//# sourceMappingURL=script.map.js